package com.lzy.webapi.controller;

import com.github.pagehelper.PageInfo;
import com.lzy.framework.component.PageBean;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.output.Result;
import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.apis.AgentProductServiceApi;
import com.lzy.product.dtos.agent.AgentProductDto;
import com.lzy.webapi.component.UserToken;
import com.lzy.webapi.facade.AgentProductFacade;
import com.lzy.webapi.request.AgentProductRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/agentProduct")
public class AgentProductController extends BaseController {
    @Autowired
    private AgentProductFacade agentProductFacade;

    /**
     * 查询产品列表数据
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/queryAgentProductList", method = RequestMethod.GET)
    @ResponseBody
    public Result queryAgentProductList(@RequestHeader("token") String token, AgentProductRequest request, Pager pager) {
        UserToken ut = isLogin(token);
        PageInfo<AgentProductDto> pageInfo = agentProductFacade.queryProductList(pager, DozerUtils.map(request, AgentProductDto.class), ut.getUserId());
        return new Result(pageInfo.getList());
    }

    /**
     * 查詢查询明細
     */
    @RequestMapping(value = "/queryAgentProductById", method = RequestMethod.GET)
    @ResponseBody
    public Result queryAgentProductById(Long id) {
        Ensure.that(id).isNotNull("04000001");
        //获取产品基本信息
        AgentProductDto agentProductDto = agentProductFacade.queryAgentProductById(id);
        return new Result(agentProductDto);
    }
}
